#ifndef FIXED_POINT_CAMERA_H_
#define FIXED_POINT_CAMERA_H_

#include "camera.h"
#include "model/matrix4x4.h"

#include <cassert>

class FixedPointCamera : public Camera{
	private:
		float theta_lr;
		float theta_ud;
	public:
		FixedPointCamera(Point at = Point(0,0,0),Point eye = Point(0.0f, 10.0f, 3.0f),Point up=Point(0,0,1))
					: Camera(	eye,
								at,
								up){
			theta_ud = 0.0f;
			theta_lr = 0.0f;
		}

		~FixedPointCamera(){

		}


		void applyCamera(){
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();

			gluLookAt(eye.x1, eye.x2, eye.x3, at.x1, at.x2, at.x3, up.x1, up.x2, up.x3);


			glTranslatef(at.x1,at.x2,at.x3);

			// Rotacion YZ(UP_DOWN)
			glRotatef(theta_ud,1,0,0);
			// Rotacion en XY(LEFT_RIGHT)
			glRotatef(theta_lr,0,0,1);

			glTranslatef(-at.x1,-at.x2,-at.x3);


		}

		void move(float offset){
			 if(offset<0)
				 offset=-1/offset;

			Matrix4x4 t1(-at.x1,-at.x2,-at.x3);
			Matrix4x4 e1(offset,offset,offset,true);
			Matrix4x4 t2(at.x1,at.x2,at.x3);
			Matrix4x4 t;
			t *= t1;
			t *= e1;
			t *= t2;

			this->eye=t*this->eye;
			this->at=t*this->at;
		}

		void rotateUD(float theta){
			this->theta_ud+=theta;
		}

		void rotateLR(float theta){
			 this->theta_lr+=theta;
		}

		void setFixedPoint(Point p){
			Point distance=p-this->at;

			Matrix4x4 t(distance.x1,distance.x2,distance.x3);

			this->eye=t*this->eye;
			this->at=t*this->at;
		}

		void updatePosition(const PathIterator& it){
			this->setFixedPoint(it.getCurrent());
		}
};

#endif /* ROTATION_CAMERA_H_ */
